package com.naiterui.ehp.bs.patient.domain;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;

/**
 * 用药提醒实体
 * @author fanjd
 * @since 1.0.0
 */
@Entity
@Table(name = "take_medication_remind")
public class MedicationRemind {

    // 二进制标签-第一个提醒 8:00
    public static final Integer LABLE_FIRST_REMIND = 1;
    // 二进制标签-第二个提醒 15:00
    public static final Integer LABLE_SECOND_REMIND = 2;
    // 二进制标签-第三个提醒 22:00
    public static final Integer LABLE_THIRD_REMIND = 4;

    private Long id; // 主键

    private Long patientId; // 患者ID

    private Integer labelType; // 发送时间标签类型:1：8:00；2.15:00；4:22:00

    private Integer times; // 提醒次数

    private Integer type; // 开启类型（0--系统1--患者）

    private String remindContent; // 药品名、用法用量的json字符串

    private Integer surplusDays;// 剩余天数（不存在数据库）

    private Date expireAt; // 过期时间

    private Date createdAt; // 创建时间

    private String createdBy; // 创建人

    private String changedBy; // 修改人

    private Date changedAt; // 修改时间

    private Integer version; // 版本

    @Id
    @Column(name = "id", unique = true, nullable = false)
    @GeneratedValue(strategy = IDENTITY)
    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "patient_id")
    public Long getPatientId() {
        return this.patientId;
    }

    public void setPatientId(Long patientId) {
        this.patientId = patientId;
    }

    @Column(name = "label_type")
    public Integer getLabelType() {
        return this.labelType;
    }

    public void setLabelType(Integer labelType) {
        this.labelType = labelType;
    }

    @Column(name = "times")
    public Integer getTimes() {
        return this.times;
    }

    public void setTimes(Integer times) {
        this.times = times;
    }

    @Column(name = "type")
    public Integer getType() {
        return this.type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    @Column(name = "remind_content")
    public String getRemindContent() {
        return this.remindContent;
    }

    public void setRemindContent(String remindContent) {
        this.remindContent = remindContent;
    }

    @Transient
    public Integer getSurplusDays() {
        return surplusDays;
    }

    public void setSurplusDays(Integer surplusDays) {
        this.surplusDays = surplusDays;
    }

    @Column(name = "expire_at")
    public Date getExpireAt() {
        return this.expireAt;
    }

    public void setExpireAt(Date expireAt) {
        this.expireAt = expireAt;
    }

    @Column(name = "created_at")
    public Date getCreatedAt() {
        return this.createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    @Column(name = "created_by")
    public String getCreatedBy() {
        return this.createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    @Column(name = "changed_by")
    public String getChangedBy() {
        return this.changedBy;
    }

    public void setChangedBy(String changedBy) {
        this.changedBy = changedBy;
    }

    @Column(name = "changed_at")
    public Date getChangedAt() {
        return this.changedAt;
    }

    public void setChangedAt(Date changedAt) {
        this.changedAt = changedAt;
    }

    @Version
    @Column(name = "version")
    public Integer getVersion() {
        return this.version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    /**
     * 验证患者是否包含指定时间的标签
     * MedicationRemind.validateLabel()
     * @Author fanjd
     * @Date 2018年1月4日
     * @since 1.0.0
     * @param label
     * @return
     */
    public boolean validateLabel(Integer label) {
        if ((this.labelType & label) == label) {
            return true;
        }
        return false;
    }

    public MedicationRemind() {
        super();
    }

    public MedicationRemind(Long patientId, Integer labelType, Integer times, Integer type, String remindContent, Date expireAt, Date createdAt,
            String createdBy, String changedBy, Date changedAt) {
        super();
        this.patientId = patientId;
        this.labelType = labelType;
        this.times = times;
        this.type = type;
        this.remindContent = remindContent;
        this.expireAt = expireAt;
        this.createdAt = createdAt;
        this.createdBy = createdBy;
        this.changedBy = changedBy;
        this.changedAt = changedAt;
    }

    @Override
    public String toString() {
        return "MedicationRemind [id=" + id + ", patientId=" + patientId + ", labelType=" + labelType + ", times=" + times + ", type=" + type
                + ", remindContent=" + remindContent + ", expireAt=" + expireAt + ", createdAt=" + createdAt + ", createdBy=" + createdBy
                + ", changedBy=" + changedBy + ", changedAt=" + changedAt + ", version=" + version + "]";
    }
}
